const { truncateSync } = require('fs');
const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/mytest',{useUnifiedTopology: true,useNewUrlParser: true})
  .then(()=> console.log('链接成功'))
  .catch(err => console.log(err,'链接失败'))

const postSchema = new mongoose.Schema({
  title:{
    type: String,
    required: [true,'plz print'],
    minlength: [2, 'min = 2'],
    maxlength: [5, 'max = 5'],
    trim: true
  }
});

const Post = mongoose.model('Post',postSchema);
Post.create({title: ' aaaa '}).then(res=>{
  console.log(res);
})

